//
//  MHProfileViewController.m
// MiaoCircle
//
//Created by acgera on 2018/4/9.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHProfileViewController.h"
#import "MHProfileHeaderCell.h"
#import "MHProfileViewModel.h"
#import "MHMomentViewModel.h"
#import "MHBindInvatiedView.h"
#import "MHBindInviterModel.h"
@interface MHProfileViewController ()
@property(nonatomic, strong) MHProfileViewModel *viewModel;
@end

@implementation MHProfileViewController
@dynamic viewModel;

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"%@" , self.title);
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem mh_backItemWithTitle:@"" imageName:@"icon_mine_setting1" target:self action:@selector(rightButtonClick)];
    self.view.backgroundColor = MH_MAIN_BACKGROUNDCOLOR_2;
    self.tableView.backgroundColor = MH_MAIN_BACKGROUNDCOLOR_2;
    [self _setupSubViews];
    
}


-(void)rightButtonClick
{
    [self.viewModel.pushDetailInfoCommand execute:nil];
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [super tableView:tableView didSelectRowAtIndexPath:indexPath];
    if (indexPath.section == 1 && indexPath.row == 0) {
        MHMomentViewModel *viewModel = [[MHMomentViewModel alloc] initWithServices:self.viewModel.services params:@{MHViewModelIsCollection:@(true),MHViewModelTitleKey:@"收藏"}];
        [self.viewModel.services pushViewModel:viewModel animated:YES];
    }
}

- (void)_setupSubViews{
    UIButton *footerView = [UIButton buttonWithType:UIButtonTypeCustom];
    footerView.mh_height = 44.0f;
    [footerView setTitle:@"退出登录" forState:UIControlStateNormal];
    [footerView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    footerView.titleLabel.font = MHRegularFont_16;
    [footerView setBackgroundImage:[UIImage yy_imageWithColor:[UIColor whiteColor]] forState:UIControlStateNormal];
    [footerView setBackgroundImage:[UIImage yy_imageWithColor:MHColor(217, 217, 217)] forState:UIControlStateHighlighted];
    self.tableView.tableFooterView = footerView;
    
    /// 事件处理
    @weakify(self);
    [[footerView rac_signalForControlEvents:UIControlEventTouchUpInside]
     subscribeNext:^(UIButton *sender) {
         @strongify(self);
         @weakify(self);
         LCActionSheet *sheet = [LCActionSheet sheetWithTitle:@"退出后不会删除任何历史数据，下次登录依然可以使用本账号" cancelButtonTitle:@"取消" clicked:^(LCActionSheet * _Nonnull actionSheet, NSInteger buttonIndex) {
             if (buttonIndex == 0) return ;
             /// 退出账号
             @strongify(self);
             [self.viewModel.logoutCommand execute:nil];
             
         } otherButtonTitles:@"退出登录", nil];
         NSMutableIndexSet *indexSet = [[NSMutableIndexSet alloc] init];
         [indexSet addIndex:1];
         sheet.destructiveButtonIndexSet = indexSet;
         [sheet show];
     }];
}

- (UIEdgeInsets)contentInset{
    return UIEdgeInsetsMake(MH_APPLICATION_TOP_BAR_HEIGHT, 0, MH_APPLICATION_TAB_BAR_HEIGHT + 5 , 0);
}

#pragma mark - Override
- (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath{
    /// 用户信息的cell
//    if (indexPath.section == 0) return [MHProfileHeaderCell cellWithTableView:tableView];
    return [super tableView:tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
}

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object{
    /// 用户信息的cell
//    if (indexPath.section == 0) {
//        MHProfileHeaderCell *profileHeaderCell = (MHProfileHeaderCell *)cell;
//        [profileHeaderCell bindViewModel:object];
//        return;
//    }
    
//    if (indexPath.section == 2 && indexPath.row == 0) {
//        __weak __typeof(self)weakSelf = self;
//        MHCommonArrowItemViewModel *item = object;
//          item.operation = ^{
//              MHBindInvatiedView *bindView = [MHBindInvatiedView mh_viewFromXib];
//              weakSelf.zh_popupController = [zhPopupController new];
//              weakSelf.zh_popupController.offsetSpacingOfKeyboard =  -100;
//              bindView.width = self.view.mh_width * 0.9;
//              bindView.layer.cornerRadius = 8.0;
//              bindView.masksToBounds = YES;
//              [bindView.closedBtn bk_whenTapped:^{
//                  [weakSelf.zh_popupController dismiss];
//              }];
//              
//              
//            
//            
//        };
//    }
    
    [super configureCell:cell atIndexPath:indexPath withObject:object];
}



@end
